class BinaryTree:
    def __init__(self,rootObj):
        self.key = rootObj
        self.leftChild = None
        self.rightChild = None
def findTree(lt):
    leftTree,rightTree=[],[]
    for i in range(len(lt)):
        # 先区分左右子树
        if lt[i][0]!='-':
            leftTree.append(int(lt[i][0]))
        else:
            leftTree.append(lt[i][0])
        if lt[i][2]!='-':
            rightTree.append(int(lt[i][2]))
        else:
            rightTree.append(lt[i][2])
    # 因为根节点不会是其他节点的子节点
    for i in range(N):
        if i not in leftTree and i not in rightTree:
            root = i;
            break
    return root,leftTree,rightTree


N=int(input())
lt=[]

for i in range(N):
    s = list(map(str, input().strip("\n")))
    lt.append(s)
# print(lt)
rootVal,leftTree, rightTree = findTree(lt)

inx=0
def builTree(rootVal):
    global inx
    if inx==N:
        return
    node = BinaryTree(rootVal)
    inx+=1
    if (leftTree[rootVal]!='-'):
        node.leftChild=builTree(leftTree[rootVal])
    if rightTree[rootVal]!='-':
        node.rightChild=builTree(rightTree[rootVal])
    return node
root=builTree(rootVal)

lst4=[]
def BFS(root):
    if root == None:
        return
    queue = []
    queue.append(root)
    while queue:
        now_node = queue.pop(0)
        if now_node.leftChild==None and now_node.rightChild==None:
            lst4.append(str(now_node.key))
        if now_node.leftChild != None:
            queue.append(now_node.leftChild)
        if now_node.rightChild != None:
            queue.append(now_node.rightChild)
BFS(root)
print(' '.join(lst4))